import type {ChatMessage} from "./message.ts";


/**
 * 群成员
 */
class GroupMember {
     userId: string;
    // 用户在群中的别名
     aliasName: string;
    // 昵称
     nickname: string;
    // 头像
     avatarUrl: string;
    // 性别
     gender: number;

    constructor(
        userId: string,
        aliasName: string,
        nickname: string,
        avatarUrl: string,
        gender: number
    ) {
        this.userId = userId;
        this.aliasName = aliasName;
        this.nickname = nickname;
        this.avatarUrl = avatarUrl;
        this.gender = gender;
    }
}


/**
 * 群组
 */
class GroupItem {
    // 主键ID
     relId: string;
    // 群号，用于搜索、添加成员等
     groupNo: string;
    // 群名称
     name: string;
    // 群头像
     avatarUrl: string;
    // 群组成员list
     users: GroupMember[] = [];

    constructor(
        relId: string,
        groupNo: string,
        name: string,
        avatarUrl: string,
        users: GroupMember[] = []
    ) {
        this.relId = relId;
        this.groupNo = groupNo;
        this.name = name;
        this.avatarUrl = avatarUrl;
        this.users = users;
    }
}

/**
 * 联系人
 */
class ContactsItem {
    relId: string; // 聊天关系ID
    // 联系人ID
     userId: string;
    // 备注名
     aliasName: string;
    // 账号
     username: string;
    // 头像
     avatarUrl: string;
    // 昵称
     nickname: string;
    // 性别
     gender: number;
    // 个人简介
     profile: string;
    // 首字母
     firstLetter: string;
     isFriend: boolean;

    constructor(
        relId: string,
        userId: string,
        aliasName: string,
        username: string,
        avatarUrl: string,
        nickname: string,
        gender: number,
        profile: string,
        firstLetter: string
    ) {
        this.relId = relId;
        this.userId = userId;
        this.aliasName = aliasName;
        this.username = username;
        this.avatarUrl = avatarUrl;
        this.nickname = nickname;
        this.gender = gender;
        this.profile = profile;
        this.firstLetter = firstLetter;
        this.isFriend = true;
    }

}


class User {
    userId: string;
    username: string;
    nickname: string; //用户名称
    avatarUrl: string; // 头像

    constructor(userId: string,username: string, nickname: string, avatarUrl: string) {
        this.userId = userId;
        this.username = username;
        this.nickname = nickname;
        this.avatarUrl = avatarUrl;
    }
}
class Chatting {
    //当前user
    user: User;
    chatter: ContactsItem | GroupItem;

    relId: string;
    showName: string;
    isGroup: boolean;
    unreadCount: number;
    messages: ChatMessage[];
    lastTime?: string;
    lastTip?: string;


    constructor(user: User, chatter: ContactsItem | GroupItem) {
        this.user = user;
        this.chatter = chatter;
        this.unreadCount = 0;
        this.messages = [];
        this.lastTime = "";
        this.lastTip = "";
        this.relId = this.chatter.relId;
        this.isGroup = ("groupNo" in chatter);
        this.showName = this.isGroup ? (this.chatter as GroupItem).name : ((this.chatter as ContactsItem).aliasName?(this.chatter as ContactsItem).aliasName:(this.chatter as ContactsItem).nickname)
    }
}

export {
    GroupMember,
    GroupItem,
    ContactsItem,
    Chatting,
    User,
}